package net.wanho.cloudprovider6001.controller;

import net.wanho.entity.User;
import net.wanho.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.net.URL;

@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Value("${server.port}")
    private String port;

    @Value("${spring.datasource.url}")
    private String str;

    @Value("${shop.share.name}")
    private String name;

    @GetMapping("/getUrl")
    public String getUrl(){
        return str+":::"+name;
    }

    @GetMapping("/test")
    public String test(){
        return "test:::port"+port;
    }

    @GetMapping()
    public AjaxResult findByName(String name){
        User user = new User(1001, name, 18);
        return AjaxResult.success(user);
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Integer id){
        return AjaxResult.success("删除成功:"+id);
    }

    @PostMapping()
    public AjaxResult addUser(@RequestBody User user){
        return AjaxResult.success("添加成功:"+user);
    }

    @PutMapping()
    public AjaxResult updateUser(@RequestBody User user){
        return AjaxResult.success("修改成功:"+user);
    }

    @GetMapping("/query")
    public AjaxResult queryUser(User user){
        return AjaxResult.success("查询成功:"+user);
    }
}
